import {fromJS} from 'immutable'
import {actionTypes} from './index'
import {getStrokeLineColor} from '@/util'

const defaultState = fromJS({
    cpuPercent: 0,
    memoryPercent: 0,
    cpuColor: '',
    memoryColor: '',
    timer:0,
    cellImgUrl:'',
    CELL0Info:false,
    CELL1Info:true,
    WAN0Info:false,
    WAN1Info:false,
    LAN0Info:false,
    LAN1Info:false,
    LAN2Info:false,
    LAN3Info:false,
    wanCount:2,
    scanData: "skjkkkk",
    version: "ST006",
    deviceModel: "st20187887ksf",
    systemTime: "2018-12-12 12:00:45",
    upTime: {
        Day:0,
        Hour:0,
        Minute:0,
    },
    hwver:"v2",
    buildTime:"2018-06-01 12:34:05",
})


export default (state = defaultState, action)=>{
    switch(action.type){
        case actionTypes.UPDATE_HOME_DATA:
            action.value.cpuColor = getStrokeLineColor(action.value.cpuPercent)
            action.value.memoryColor = getStrokeLineColor(action.value.memoryPercent)
            return state.merge(action.value)
        case actionTypes.CHANGE_TIMER:
            return state.set('timer',action.value)
        default:
            return state
    }
}
